import requests
import parsel
for i in range(1,10):
    url='https://www.umei.cc/meinvtupian/meinvxiezhen/{}.htm'.format(i)
    headers = {
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
        'cookie':'UM_distinctid=1716941d927652-0fb3ea40be025c-335e4e71-144000-1716941d929197; __login_his_sync=0; tourist_expires=1; Hm_lvt_407473d433e871de861cf818aa1405a1=1586608862; _GUID=d8eec002-35da-1ad7-ac12-9ca1c3cb4309; CNZZDATA1261814609=674853875-1586608471-https%253A%252F%252Fwww.mkzhan.com%252F%7C1586608471; readMode=scroll; CNZZDATA1262045698=1069876723-1586605088-https%253A%252F%252Fwww.baidu.com%252F%7C1586607119; redirect_url=%2F211692%2F; Hm_lpvt_407473d433e871de861cf818aa1405a1=1586610847; cn_1262045698_dplus=%7B%22distinct_id%22%3A%20%221716941d927652-0fb3ea40be025c-335e4e71-144000-1716941d929197%22%2C%22%24_sessionid%22%3A%200%2C%22%24_sessionTime%22%3A%201586610857%2C%22%24dp%22%3A%200%2C%22%24_sessionPVTime%22%3A%201586610857%7D',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
        'referer': 'https://www.mkzhan.com/search/?keyword=%E6%96%97%E7%BD%97%E5%A4%A7%E9%99%86'
    }
    reponse=requests.get(url,headers=headers)
    reponse.encoding=reponse.apparent_encoding
    html=reponse.text
    pase=parsel.Selector(html)
    href_list=pase.xpath('//div[@class="TypeList"]/ul/li/a/@href').extract()
    # print(href_list)
    for href in href_list:
        href_data=requests.get(href,headers=headers)
        href_data.encoding=href_data.apparent_encoding
        href_data1=href_data.text
        img=parsel.Selector(href_data1)
        img_usrc=img.xpath('//div[@class="ImageBody"]/p/a/img/@src').extract_first()
        img_title=img.xpath('//div[@class="ImageBody"]/p/a/img/@alt').extract_first()+img_usrc.split('/')[-1]
        # print(img_title,img_usrc)
        img_data=requests.get(img_usrc,headers=headers)
        img_data.encoding=img_data.apparent_encoding
        html1=img_data.text
        pase1=parsel.Selector(html1)
        img_src=pase1.xpath('//div[@class="ImageBody"]/p/a/img/@src').extract_first()
        print(img_usrc)


        # with open('搞笑//'+img_title,'wb')as f:
        #     print('正在保存',img_title)
        #     f.write(img_data)
        #     print('保存完毕')